package com.master.common.baseService.message;

import com.master.constant.model.SysChargeNotice;
import com.master.constant.model.SysRMQMessage;
import com.master.constant.model.SysRepairNotice;
import com.master.constant.model.SysSmsCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.annotation.RabbitListeners;
import org.springframework.stereotype.Component;


/**
 * @author Heath.Que
 * @version 1.0
 * @classname ReceiveMessageService
 * @description 住户接收 通告、收费、维修等相关消息
 * @Date 2021/6/4 16:38
 **/
@Component
@RabbitListeners(value = {@RabbitListener(queues = "NoticeDirectQueue"), @RabbitListener(queues = "chargeDirectQueue"),
        @RabbitListener(queues = "RepairDirectQueue")})
public class ReceiveMessageService {
    private final static Logger logger = LoggerFactory.getLogger(ReceiveMessageService.class);

    @RabbitHandler
    public Boolean receiveMessage(SysRMQMessage rmqMessage){
        boolean mark = false;
        try {
            //获取消息类型做出相对应的处理
            String dealType = rmqMessage.getMessageType();
            switch (dealType){
                case "message": messageDeal(rmqMessage.getMessageBody());
                break;
                case "charge": chargeDeal(rmqMessage.getMessageBody());
                break;
                case "repair": repairDeal(rmqMessage.getMessageBody());
                break;
            }

            mark = true;
        }catch (Exception e){
            logger.error(e.getMessage());
        }

        return mark;
    }

    //短信消息处理
    public void messageDeal (Object message){
        SysSmsCode smsCode = (SysSmsCode) message;


    }

    //收费消息处理
    public void chargeDeal (Object message){
        SysChargeNotice chargeNotice = (SysChargeNotice) message;
    }

    //维修单消息处理
    public void repairDeal (Object message){
        SysRepairNotice repairNotice = (SysRepairNotice) message;
    }
}
